<template>
  <div class="msgsendlog-container">
    <!-- 搜索工作栏 -->
    <ContentWrap class="search-wrapper">
      <!-- 搜索头部 -->
      <div class="search-header">
        <div class="header-icon">
          <Icon icon="ep:message" />
        </div>
        <div class="header-content">
          <h3 class="search-title">消息发送记录</h3>
          <p class="search-subtitle">查看企业微信消息发送历史和结果</p>
        </div>
      </div>

      <!-- 搜索表单 -->
      <div class="search-form-container">
        <el-form
          :model="queryParams"
          ref="queryFormRef"
          :inline="true"
          label-width="100px"
          label-position="left"
          class="enhanced-search-form"
        >
          <div class="form-grid">
            <el-form-item label="消息类型" prop="msgType" class="form-item">
              <el-select
                v-model="queryParams.msgType"
                placeholder="请选择消息类型"
                clearable
                class="enhanced-select"
              >
                <template #prefix>
                  <Icon icon="ep:message" />
                </template>
                <el-option label="普通消息" :value="1" />
                <el-option label="定时任务" :value="2" />
              </el-select>
            </el-form-item>

            <el-form-item label="发送类型" prop="chatType" class="form-item">
              <el-select
                v-model="queryParams.chatType"
                placeholder="请选择发送类型"
                clearable
                class="enhanced-select"
              >
                <template #prefix>
                  <Icon icon="ep:user" />
                </template>
                <el-option label="普通客户" value="single" />
                <el-option label="客户群" value="group" />
              </el-select>
            </el-form-item>

            <el-form-item label="创建时间" prop="createTime" class="form-item">
              <el-date-picker
                v-model="queryParams.createTime"
                value-format="YYYY-MM-DD HH:mm:ss"
                type="daterange"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
                class="enhanced-date-picker"
              />
            </el-form-item>
          </div>

          <div class="form-actions">
            <el-button @click="handleQuery" class="search-btn">
              <Icon icon="ep:search" class="btn-icon" />
              搜索
            </el-button>
            <el-button @click="resetQuery" class="reset-btn">
              <Icon icon="ep:refresh" class="btn-icon" />
              重置
            </el-button>
            <el-button
              type="primary"
              plain
              @click="openForm('create')"
              v-hasPermi="['wecom:msg-send-log:create']"
              class="add-btn"
            >
              <Icon icon="ep:plus" class="btn-icon" />
              新增消息
            </el-button>
          </div>
        </el-form>
      </div>
    </ContentWrap>

    <!-- 列表 -->
    <ContentWrap class="table-wrapper">
      <!-- 表格头部 -->
      <div class="table-header">
        <div class="header-icon">
          <Icon icon="ep:list" />
        </div>
        <div class="header-content">
          <h4 class="table-title">发送记录</h4>
          <p class="table-subtitle">共 {{ total }} 条记录</p>
        </div>
      </div>

      <!-- 表格容器 -->
      <div class="table-container">
        <el-table
          v-loading="loading"
          :data="list"
          :stripe="true"
          :show-overflow-tooltip="true"
          class="enhanced-table"
          :header-cell-style="{ background: '#f8f9ff', color: '#303133', fontWeight: '600' }"
        >
          <el-table-column label="消息类型" align="center" prop="msgType" width="120">
            <template #default="scope">
              <el-tag :type="scope.row.msgType == 1 ? 'primary' : 'warning'" class="msg-type-tag">
                <Icon :icon="scope.row.msgType == 1 ? 'ep:message' : 'ep:timer'" class="tag-icon" />
                {{ scope.row.msgType == 1 ? '普通消息' : '定时任务' }}
              </el-tag>
            </template>
          </el-table-column>

          <el-table-column label="发送类型" align="center" prop="chatType" width="120">
            <template #default="scope">
              <el-tag
                :type="scope.row.chatType == 'single' ? 'success' : 'info'"
                class="chat-type-tag"
              >
                <Icon
                  :icon="scope.row.chatType == 'single' ? 'ep:user' : 'ep:user-filled'"
                  class="tag-icon"
                />
                {{ scope.row.chatType == 'single' ? '普通客户' : '客户群' }}
              </el-tag>
            </template>
          </el-table-column>

          <el-table-column
            label="客户ID集合或群ID集合"
            align="center"
            prop="toUserNameList"
            min-width="200"
          >
            <template #default="scope">
              <div class="id-list-cell">
                <Icon icon="ep:collection-tag" class="id-icon" />
                <span class="id-text">{{ scope.row.toUserNameList || '-' }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="发送人" align="center" prop="sender" min-width="120">
            <template #default="scope">
              <div class="sender-cell">
                <Icon icon="ep:user" class="sender-icon" />
                <span class="sender-name">{{ scope.row.sender || '-' }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="发送内容" align="center" prop="content" min-width="200">
            <template #default="scope">
              <div class="content-cell">
                <el-tooltip :content="scope.row.content" placement="top">
                  <span class="content-text">{{ scope.row.content || '-' }}</span>
                </el-tooltip>
              </div>
            </template>
          </el-table-column>

          <el-table-column
            label="创建时间"
            align="center"
            prop="createTime"
            :formatter="dateFormatter"
            width="180"
          >
            <template #default="scope">
              <div class="time-cell">
                <Icon icon="ep:clock" class="time-icon" />
                <span>{{ dateFormatter(scope.row, null, scope.row.createTime) }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="操作" align="center" width="150" fixed="right">
            <template #default="scope">
              <div class="action-buttons">
                <el-button
                  link
                  type="primary"
                  @click="checkRes(scope.row.id)"
                  v-hasPermi="['wecom:msg-send-log:update']"
                  class="result-btn"
                >
                  <Icon icon="ep:view" class="btn-icon" />
                  查看结果
                </el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!-- 分页 -->
      <div class="pagination-wrapper">
        <Pagination
          :total="total"
          v-model:page="queryParams.pageNo"
          v-model:limit="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </ContentWrap>

    <!-- 表单弹窗：添加/修改 -->
    <MsgSendLogForm ref="formRef" @success="getList" />

    <!-- 群发结果弹窗 -->
    <Dialog
      @close="handleClose"
      title="群发结果"
      v-model="sendResultVisible"
      width="650"
      class="enhanced-dialog"
    >
      <!-- 弹窗头部 -->
      <div class="result-header">
        <div class="header-icon">
          <Icon icon="ep:data-analysis" />
        </div>
        <div class="header-content">
          <h4 class="result-title">发送结果详情</h4>
          <p class="result-subtitle">查看消息发送状态和详细信息</p>
        </div>
      </div>

      <!-- 结果表格 -->
      <div class="result-table-container">
        <el-table
          ref="tableRef"
          max-height="450"
          border
          :header-cell-style="{ background: '#f8f9ff', color: '#303133', fontWeight: '600' }"
          v-loading="sendResLoading"
          :data="sendResList"
          :stripe="true"
          class="result-table"
        >
          <el-table-column label="名称" align="center" prop="weCustomerId" min-width="150">
            <template #default="scope">
              <div class="name-cell">
                <Icon
                  :icon="chatType == 'single' ? 'ep:user' : 'ep:user-filled'"
                  class="name-icon"
                />
                <span class="name-text">
                  <span v-if="chatType == 'single'">{{
                    listMap[scope.row.weCustomerId]?.name || '-'
                  }}</span>
                  <span v-if="chatType == 'group'">{{
                    listMap[scope.row.chatId]?.name || '-'
                  }}</span>
                </span>
              </div>
            </template>
          </el-table-column>

          <el-table-column label="发送状态" align="center" prop="status" width="180">
            <template #default="scope">
              <el-tag :type="StatusMap[scope.row.status].type" class="status-tag">
                <Icon :icon="getStatusIcon(scope.row.status)" class="status-icon" />
                {{ StatusMap[scope.row.status].text }}
              </el-tag>
            </template>
          </el-table-column>

          <el-table-column
            label="发送时间"
            align="center"
            prop="sendTime"
            :formatter="dateFormatter"
            width="180"
          >
            <template #default="scope">
              <div class="send-time-cell">
                <Icon icon="ep:clock" class="time-icon" />
                <span>{{ dateFormatter(scope.row, null, scope.row.sendTime) }}</span>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!-- 查看更多按钮 -->
      <div class="load-more-container">
        <el-button
          v-if="nextCursor"
          type="primary"
          @click="checkRes(checkId)"
          class="load-more-btn"
        >
          <Icon icon="ep:arrow-down" class="btn-icon" />
          查看更多
        </el-button>
      </div>
    </Dialog>
  </div>
</template>

<script setup lang="ts">
import * as MsgSendLogApi from '@/api/wecom/msgsendlog'
import MsgSendLogForm from './MsgSendLogForm.vue'
import { dateFormatter } from '@/utils/formatTime'

defineOptions({ name: 'MsgSendLog' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const total = ref(0) // 列表的总页数
const list = ref([]) // 列表的数据
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  msgType: null,
  chatType: null,
  toUserList: null,
  sender: null,
  content: null,
  msgid: null,
  createTime: []
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

// 获取状态图标
const getStatusIcon = (status: number) => {
  const iconMap = {
    0: 'ep:clock',
    1: 'ep:check',
    2: 'ep:close',
    3: 'ep:warning'
  }
  return iconMap[status] || 'ep:question'
}

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await MsgSendLogApi.getMsgSendLogPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
  formRef.value.open(type, id)
}

/** 删除按钮操作 */
const handleDelete = async (id: number) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await MsgSendLogApi.deleteMsgSendLog(id)
    message.success(t('common.delSuccess'))
    // 刷新列表
    await getList()
  } catch {}
}

/** 查看群发结果 */
const checkId = ref(null) // 记录当前点击的数据
const sendResLoading = ref(true) // 加载
const sendResList = ref([]) // table数据
const moreList = ref([])
const sendResultVisible = ref(false) // dialog的显隐控制
const StatusMap = {
  0: {
    text: '未发送',
    type: 'info'
  },
  1: {
    text: '已发送',
    type: 'success'
  },
  2: {
    text: '因客户不是好友导致发送失败',
    type: 'danger'
  },
  3: {
    text: '因客户已经收到其他群发消息导致发送失败',
    type: 'danger'
  }
}
const tableRef = ref()
const listMap = ref({}) // 获取到的客户的数据
const chatType = ref()
const ids = ref([]) // 获取需要转换的ids
const nextCursor = ref(null) // 查看更多的指标
const checkRes = async (id) => {
  // 点击查看群发结果的按钮方法
  sendResLoading.value = true
  checkId.value = id
  try {
    sendResultVisible.value = true
    const params = {
      id,
      cursor: nextCursor.value
    }
    const data = await MsgSendLogApi.getSendResult(params)
    if (data == null) return
    sendResList.value = data.data
    if (data.nextCursor || nextCursor.value) {
      // 可以查看更多
      nextCursor.value = data.nextCursor
      if (moreList.value.length == 0) {
        moreList.value = JSON.parse(JSON.stringify(sendResList.value))
      } else {
        nextTick(() => scrollToColumn(data.data[0].weCustomerId))
        moreList.value = moreList.value.concat(data.data)
        sendResList.value = moreList.value
      }
    }

    ids.value = []
    sendResList.value.map((i) => {
      ids.value.push(i.weCustomerId || i.chatId)
    })
    chatType.value = data.chatType
    if (data.chatType == 'group') {
      const mapData = await MsgSendLogApi.getChatMap(ids.value)
      listMap.value = mapData
    }
    if (data.chatType == 'single') {
      const mapData = await MsgSendLogApi.getCustomerMap(ids.value)
      listMap.value = mapData
    }
  } finally {
    sendResLoading.value = false
  }
}
/** 弹窗关闭时 重置 */
const handleClose = () => {
  checkId.value = null
  sendResList.value = []
  moreList.value = []
  nextCursor.value = null
}

/** 滚动到最新加载到的第一行 */
const scrollToColumn = (id) => {
  try {
    const rowHeightList = []
    let temp = tableRef.value.$el.getElementsByClassName('el-table__row') //获取到的都是元素
    for (let i = 0; i < temp.length; i++) {
      const item = temp[i]
      rowHeightList.push(item.scrollHeight)
    }
    let rowIndex = 0
    for (let i = 0; i < sendResList.value.length; i++) {
      const item = sendResList.value[i]
      if (item.weCustomerId == id) {
        rowIndex = i
        break
      }
    }
    let totalHeight = 0
    for (let index = 0; index < rowHeightList.length; index++) {
      const row = rowHeightList[index]
      if (index < rowIndex) {
        totalHeight += row
      }
    }
    // 滚动到指定行
    tableRef.value.setScrollTop(totalHeight)
  } catch (error) {
    console.error('错误', error)
  }
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>

<style lang="scss" scoped>
// 主题色变量
$primary-color: #0052cc;
$primary-light: rgba(0, 82, 204, 0.1);
$primary-border: rgba(0, 82, 204, 0.3);
$success-color: #67c23a;
$warning-color: #e6a23c;
$danger-color: #f56c6c;
$info-color: #909399;
$text-primary: #303133;
$text-regular: #606266;
$text-secondary: #909399;
$text-placeholder: #c0c4cc;
$border-color: #dcdfe6;
$border-light: #e4e7ed;
$bg-color: #f5f7fa;
$shadow-light: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
$shadow-base:
  0 2px 4px rgba(0, 0, 0, 0.12),
  0 0 6px rgba(0, 0, 0, 0.04);
$border-radius: 12px;
$border-radius-small: 8px;

.msgsendlog-container {
  padding: 16px;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  min-height: 100vh;

  @media (max-width: 768px) {
    padding: 8px;
  }
}

/* 搜索区域样式 */
.search-wrapper {
  margin-bottom: 16px;
  border-radius: $border-radius;
  overflow: hidden;
  box-shadow: $shadow-light;
  border: 1px solid $border-light;

  :deep(.el-card__body) {
    padding: 0;
  }
}

.search-header {
  display: flex;
  align-items: center;
  padding: 20px 24px;
  background: linear-gradient(135deg, $primary-color 0%, #1d4ed8 100%);
  color: white;
  border-bottom: 1px solid $border-light;

  @media (max-width: 768px) {
    padding: 16px;
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }
}

.header-icon {
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: $border-radius-small;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;

  @media (max-width: 768px) {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }
}

.header-content {
  flex: 1;
  margin-left: 16px;

  @media (max-width: 768px) {
    margin-left: 0;
  }
}

.search-title {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 4px 0;

  @media (max-width: 768px) {
    font-size: 18px;
  }
}

.search-subtitle {
  font-size: 14px;
  opacity: 0.9;
  margin: 0;

  @media (max-width: 768px) {
    font-size: 12px;
  }
}

.search-form-container {
  background: white;
  padding: 24px;

  @media (max-width: 768px) {
    padding: 16px;
  }
}

.enhanced-search-form {
  .form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 20px;

    @media (max-width: 768px) {
      grid-template-columns: 1fr;
      gap: 16px;
    }
  }

  .form-item {
    margin-bottom: 0;

    :deep(.el-form-item__label) {
      font-weight: 500;
      color: $text-regular;
    }
  }
}

.enhanced-select,
.enhanced-date-picker {
  width: 100%;

  :deep(.el-input__wrapper) {
    border-radius: $border-radius-small;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;

    &:hover {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.1);
    }

    &.is-focus {
      box-shadow: 0 4px 12px rgba(0, 82, 204, 0.2);
    }
  }
}

.form-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;

  @media (max-width: 768px) {
    flex-direction: column;
  }
}

.search-btn {
  background: linear-gradient(135deg, $primary-color 0%, #1d4ed8 100%);
  border: none;
  border-radius: $border-radius-small;
  padding: 10px 20px;
  font-weight: 500;
  color: white;
  transition: all 0.3s ease;

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 82, 204, 0.3);
  }

  @media (max-width: 768px) {
    width: 100%;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

.reset-btn {
  border: 2px solid $border-color;
  color: $text-regular;
  border-radius: $border-radius-small;
  padding: 10px 20px;
  font-weight: 500;
  transition: all 0.3s ease;

  &:hover {
    border-color: $primary-color;
    color: $primary-color;
    background: $primary-light;
  }

  @media (max-width: 768px) {
    width: 100%;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

.add-btn {
  border: 2px solid $primary-color;
  color: $primary-color;
  border-radius: $border-radius-small;
  padding: 10px 20px;
  font-weight: 500;
  transition: all 0.3s ease;

  &:hover {
    background: $primary-light;
    transform: translateY(-1px);
  }

  @media (max-width: 768px) {
    width: 100%;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

/* 表格区域样式 */
.table-wrapper {
  border-radius: $border-radius;
  overflow: hidden;
  box-shadow: $shadow-light;
  border: 1px solid $border-light;

  :deep(.el-card__body) {
    padding: 0;
  }
}

.table-header {
  display: flex;
  align-items: center;
  padding: 20px 24px;
  background: linear-gradient(135deg, #f8f9ff 0%, #f0f2ff 100%);
  border-bottom: 1px solid $border-light;

  @media (max-width: 768px) {
    padding: 16px;
  }

  .header-icon {
    width: 40px;
    height: 40px;
    background: $primary-color;
    border-radius: $border-radius-small;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    flex-shrink: 0;

    @media (max-width: 768px) {
      width: 36px;
      height: 36px;
      font-size: 16px;
    }
  }

  .header-content {
    flex: 1;
    margin-left: 12px;

    @media (max-width: 768px) {
      margin-left: 10px;
    }
  }

  .table-title {
    font-size: 16px;
    font-weight: 600;
    color: $text-primary;
    margin: 0 0 2px 0;

    @media (max-width: 768px) {
      font-size: 14px;
    }
  }

  .table-subtitle {
    font-size: 13px;
    color: $text-secondary;
    margin: 0;

    @media (max-width: 768px) {
      font-size: 12px;
    }
  }
}

.table-container {
  background: white;
  overflow-x: auto;
}

.enhanced-table {
  :deep(.el-table__header) {
    th {
      background: linear-gradient(135deg, #f8f9ff 0%, #f0f2ff 100%) !important;
      color: $text-primary !important;
      font-weight: 600 !important;
      border-bottom: 2px solid $primary-light;
      padding: 16px 12px;
    }
  }

  :deep(.el-table__body) {
    tr {
      transition: all 0.3s ease;

      &:hover {
        background: $primary-light !important;
      }

      td {
        padding: 14px 12px;
        border-bottom: 1px solid $border-light;
      }
    }

    .el-table__row--striped {
      background: #fafbff;

      &:hover {
        background: $primary-light !important;
      }
    }
  }

  // H5适配
  @media (max-width: 768px) {
    :deep(.el-table__header) th {
      padding: 12px 8px;
      font-size: 13px;
    }

    :deep(.el-table__body) td {
      padding: 12px 8px;
      font-size: 12px;
    }
  }
}

/* 表格单元格样式 */
.msg-type-tag,
.chat-type-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 12px;
  padding: 4px 8px;

  .tag-icon {
    font-size: 12px;
  }
}

.id-list-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}

.id-icon {
  color: $primary-color;
  font-size: 14px;
  flex-shrink: 0;
}

.id-text {
  font-size: 12px;
  color: $text-regular;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sender-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
}

.sender-icon {
  color: $primary-color;
  font-size: 14px;
  flex-shrink: 0;
}

.sender-name {
  font-weight: 500;
  color: $text-primary;
}

.content-cell {
  max-width: 200px;
}

.content-text {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  color: $text-regular;
}

.time-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  font-size: 12px;
  color: $text-secondary;
}

.time-icon {
  color: $text-secondary;
  font-size: 14px;
}

.action-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.result-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.3s ease;

  &:hover {
    background: $primary-light;
    transform: scale(1.05);
  }

  .btn-icon {
    font-size: 12px;
  }
}

/* 分页样式 */
.pagination-wrapper {
  display: flex;
  justify-content: center;
  padding: 20px 24px;
  background: white;
  border-top: 1px solid $border-light;

  @media (max-width: 768px) {
    padding: 16px;
  }

  :deep(.el-pagination) {
    .el-pager li {
      border-radius: 6px;
      margin: 0 2px;
      transition: all 0.3s ease;

      &:hover {
        background: $primary-light;
        color: $primary-color;
      }

      &.is-active {
        background: $primary-color;
        color: white;
      }
    }

    .btn-prev,
    .btn-next {
      border-radius: 6px;
      transition: all 0.3s ease;

      &:hover {
        background: $primary-light;
        color: $primary-color;
      }
    }

    @media (max-width: 768px) {
      .el-pagination__sizes,
      .el-pagination__jump {
        display: none;
      }
    }
  }
}

/* 弹窗样式 */
.enhanced-dialog {
  :deep(.el-dialog) {
    border-radius: $border-radius;
    overflow: hidden;

    @media (max-width: 768px) {
      width: 95% !important;
      margin: 0 auto;
    }
  }

  :deep(.el-dialog__header) {
    padding: 0;
    border-bottom: none;
  }

  :deep(.el-dialog__body) {
    padding: 0;
  }

  :deep(.el-dialog__headerbtn) {
    top: 16px;
    right: 16px;
    z-index: 10;

    .el-dialog__close {
      color: white;
      font-size: 18px;

      &:hover {
        color: rgba(255, 255, 255, 0.8);
      }
    }
  }
}

.result-header {
  display: flex;
  align-items: center;
  padding: 20px 24px;
  background: linear-gradient(135deg, $primary-color 0%, #1d4ed8 100%);
  color: white;

  @media (max-width: 768px) {
    padding: 16px 20px;
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }

  .header-icon {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: $border-radius-small;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;

    @media (max-width: 768px) {
      width: 36px;
      height: 36px;
      font-size: 16px;
    }
  }

  .header-content {
    flex: 1;
    margin-left: 12px;

    @media (max-width: 768px) {
      margin-left: 0;
    }
  }

  .result-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 4px 0;

    @media (max-width: 768px) {
      font-size: 16px;
    }
  }

  .result-subtitle {
    font-size: 13px;
    opacity: 0.9;
    margin: 0;

    @media (max-width: 768px) {
      font-size: 12px;
    }
  }
}

.result-table-container {
  background: white;
  overflow-x: auto;
}

.result-table {
  :deep(.el-table__header) {
    th {
      background: linear-gradient(135deg, #f8f9ff 0%, #f0f2ff 100%) !important;
      color: $text-primary !important;
      font-weight: 600 !important;
      border-bottom: 2px solid $primary-light;
    }
  }

  :deep(.el-table__body) {
    tr {
      &:hover {
        background: $primary-light !important;
      }
    }
  }
}

.name-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}

.name-icon {
  color: $primary-color;
  font-size: 14px;
  flex-shrink: 0;
}

.name-text {
  font-weight: 500;
  color: $text-primary;
}

.status-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 12px;
  padding: 4px 8px;

  .status-icon {
    font-size: 12px;
  }
}

.send-time-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  font-size: 12px;
  color: $text-secondary;
}

.load-more-container {
  display: flex;
  justify-content: center;
  padding: 20px;
  background: white;
  border-top: 1px solid $border-light;

  @media (max-width: 768px) {
    padding: 16px;
  }
}

.load-more-btn {
  background: linear-gradient(135deg, $primary-color 0%, #1d4ed8 100%);
  border: none;
  border-radius: $border-radius-small;
  padding: 10px 20px;
  font-weight: 500;
  width: 200px;
  transition: all 0.3s ease;

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 82, 204, 0.3);
  }

  @media (max-width: 768px) {
    width: 100%;
  }

  .btn-icon {
    margin-right: 6px;
  }
}

/* 响应式优化 */
@media (max-width: 480px) {
  .msgsendlog-container {
    padding: 4px;
  }

  .search-form-container {
    padding: 12px;
  }

  .form-actions {
    gap: 8px;

    .el-button {
      padding: 8px 12px;
      font-size: 13px;
    }
  }

  .enhanced-table {
    :deep(.el-table__header) th {
      padding: 10px 6px;
      font-size: 12px;
    }

    :deep(.el-table__body) td {
      padding: 10px 6px;
      font-size: 11px;
    }
  }

  .pagination-wrapper {
    padding: 12px;
  }

  .load-more-container {
    padding: 12px;
  }
}

/* 加载状态优化 */
:deep(.el-loading-mask) {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(2px);

  .el-loading-spinner {
    .path {
      stroke: $primary-color;
    }
  }
}

/* 深色模式适配 */
@media (prefers-color-scheme: dark) {
  .msgsendlog-container {
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
  }

  .search-wrapper,
  .table-wrapper {
    background: #374151;
    border-color: #4b5563;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  }

  .search-form-container,
  .table-container,
  .pagination-wrapper {
    background: #374151;
  }

  .table-header {
    background: #4b5563;
    border-color: #6b7280;
  }

  .search-title,
  .table-title {
    color: #f9fafb;
  }

  .sender-name,
  .name-text {
    color: #f9fafb;
  }

  .content-text {
    color: #d1d5db;
  }

  .enhanced-table {
    :deep(.el-table__header) {
      th {
        background: #4b5563 !important;
        color: #f9fafb !important;
        border-bottom-color: #6b7280;
      }
    }

    :deep(.el-table__cell) {
      border-bottom-color: #4b5563;
    }
  }

  .result-table-container,
  .load-more-container {
    background: #374151;
  }

  .result-table {
    :deep(.el-table__header) {
      th {
        background: #4b5563 !important;
        color: #f9fafb !important;
        border-bottom-color: #6b7280;
      }
    }
  }
}
</style>
